using System;
using System.Linq.Expressions;
using FastMapper.Core;
using FastMapper.Helpers;

namespace FastMapper.Configuration
{
    public class PropertyMapConfigurator<TSource> : IPropertyMapConfigurator<TSource>
    {
        public PropertyMapConfigurator(TypeInfo typeInfo,MemberInfoNode destinationPropertyInfo)
        {
            Parent = typeInfo;
            DestinationPropertyInfo = destinationPropertyInfo;
        }

        private bool _isIgnored = false;

        public TypeInfo Parent { get; private set; }

        public MemberInfoNode SourcePropertyInfo
        {
            get; 
            private set;
        }
        public MemberInfoNode DestinationPropertyInfo
        {
            get; 
            private set;
        }

        public bool IsIgnored
        {
            get { return _isIgnored; }
        }

        public void Ignore()
        {
            _isIgnored = true;
        }

        public void MapFrom<TMember>(Expression<Func<TSource, TMember>> sourceMember)
        {
            var sourceMemberNode = sourceMember.GetMemberInfoFromRoot();
            if(sourceMember == null)
                throw  new InvalidOperationException();
            SourcePropertyInfo = sourceMemberNode;
        }
    }
}